<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px" :rules="rules">
      <el-form-item label="销售订单号" prop="sellformCode">
        <el-input
          v-model="queryParams.sellformCode"
          placeholder="请输入销售订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提交人" prop="submittername">
        <el-input
          v-model="queryParams.submittername"
          placeholder="请输入提交人名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入部门名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" clearable value-format="yyyy-MM-dd" type="date" placeholder="请选择日期" size="mini"/>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="overdueList">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="日期" align="center" prop="createTime"/>
      <el-table-column label="销售订单号" align="center" prop="sellformCode" width="80">
        <template slot-scope="scope">
          <span @click="viewIt(scope.row.sellformId)" style="cursor: pointer;color: #00afff">{{scope.row.sellformCode}}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户" align="center" prop="customerName" width="250"/>
      <el-table-column label="结算金额" align="center" prop="settlementAmount" />
      <el-table-column label="出库日期" align="center" prop="loadDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loadDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预计账期" align="center" prop="expectPayDays" width="80">
        <template slot-scope="scope">
          <span >{{scope.row.expectPayDays}}天</span>
        </template>
      </el-table-column>
      <el-table-column label="逾期日期" align="center" prop="overdueDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.overdueDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="逾期天数" align="center" prop="overdueDays" width="80">
        <template slot-scope="scope">
          <span>{{scope.row.overdueDays}}天</span>
        </template>
      </el-table-column>

      <el-table-column label="提交人" align="center" prop="submittername" />
      <el-table-column label="部门" align="center" prop="deptName" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { listOverdue, getOverdue, delOverdue, addOverdue, updateOverdue, exportOverdue } from "@/api/customer/overdue";
import { parseTime } from '@/utils/ruoyi'

export default {
  name: "Overdue",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售订单逾期信息表格数据
      overdueList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sellformId: null,
        sellformCode: null,
        customerId: null,
        customerName: null,
        deptId: null,
        deptName: null,
        submitterid: null,
        submittername: null,
        settlementAmount: null,
        loadDate: null,
        expectPayDays: null,
        overdueDays: null,
        overdueDate: null,
        createTime:this.getDate().join('-'),
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // createTime: [{required:true,message:"请选择开始日期",trigger:"blur"},]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //获取当前日期
    getDate: function (dayCount = 0) {
      var dd = new Date();
      // console.log('olddd:--',dd)
      dd.setTime(dd.getTime()-24*60*60*1000);
      // var s1 = dd.getFullYear()+"-" + (dd.getMonth()+1) + "-" + dd.getDate();
      // console.log('newS1:--',s1)
      dd.setDate(dd.getDate()+dayCount);//设置日期
      var y = dd.getFullYear();
      var m = dd.getMonth() + 1;//获取当前月份的日期
      var fullM = m.toString().length == 2 ? m : '0' + m;
      var d = dd.getDate();
      // return y+"-"+fullM+"-"+d;
      return [y, fullM, d];
    },
    viewIt(id){
      this.$router.push({path:'/bill/sellforminfo',query:{id:id}})
    },
    /** 查询销售订单逾期信息列表 */
    getList() {
      console.log(parseTime(new Date(),'{y}-{m}-{d}'))
      this.loading = true;
      listOverdue(this.queryParams).then(response => {
        this.overdueList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sellformId: null,
        sellformCode: null,
        customerId: null,
        customerName: null,
        deptId: null,
        deptName: null,
        submitterid: null,
        submittername: null,
        settlementAmount: null,
        loadDate: null,
        expectPayDays: null,
        overdueDays: null,
        overdueDate: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.id)
    //   this.single = selection.length!==1
    //   this.multiple = !selection.length
    // },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加销售订单逾期信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOverdue(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改销售订单逾期信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOverdue(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOverdue(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有销售订单逾期信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportOverdue(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
